﻿/*----------------------------------------------------------------
// Copyright (C) 2011 周士祎
// 版权所有。 
//
// 文件名：LoggingInfo
// 文件功能描述：登录管理
//
// 
// 创建标识：2012-01-02 周士祎
//
// 修改标识：
// 修改描述：
//
//
//----------------------------------------------------------------*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DAO.WaiGaoQiao;

namespace Model.WaiGaoQiao
{
    /// <summary>
    /// 登录注册用户
    /// </summary>
    public class LoggingInfo
    {
        /// <summary>
        /// 登录名称
        /// </summary>
        public string LogName
        {
            get;
            set;
        }
        /// <summary>
        /// 登录密码
        /// </summary>
        public string LogPassword
        {
            get;
            set;
        }
        /// <summary>
        /// 密码确认
        /// </summary>
        public string PasswordConfirm
        {
            get;
            set;
        }
        /// <summary>
        /// 密码提示
        /// </summary>
        public string PasswordHint
        {
            get;
            set;
        }
        /// <summary>
        /// 登录时间
        /// </summary>
        public DateTime LogDt
        {
            get;
            set;
        }
        /// <summary>
        /// 是否锁定
        /// </summary>
        public string IsLocked
        {
            get;
            set;
        }
        /// <summary>
        /// 锁定时间
        /// </summary>
        public DateTime? LockDt
        {
            get;
            set;
        }
        /// <summary>
        /// 角色名称
        /// </summary>
        public string RoleName
        {
            get;
            set;
        }
        private int LogUserCount;
        public int _LogUserCount
        {
            get
            {
                return LogUserCount;
            }
        }
        public LoggingInfo(bool isgetcount)
        {
            if (isgetcount)
            {
                LogUserCount = GetLogCount();
            }
        }

        public LoggingInfo()
        { }

        public string getlogpassword(string logname)
        {
            DataAccessLogging dalog = new DataAccessLogging();
            return dalog.Da_Getlogpassword(logname);
        }
        public int DeleteLog(string logid)
        {
            DataAccessLogging dalog = new DataAccessLogging();
            return dalog.DeleteLogUser(logid);
        }
        /// <summary>
        /// 保存登录用户信息
        /// </summary>
        /// <param name="loginfo"></param>
        /// <returns></returns>
        public int SaveLog(LoggingInfo loginfo)
        {
            object[] paralog = new object[] { loginfo.LogName,loginfo.LogPassword,loginfo.PasswordConfirm,
                                              loginfo.PasswordHint};
            DataAccessLogging dalog = new DataAccessLogging();
            return dalog.Save(paralog);
        }
        /// <summary>
        /// 获取登录列表
        /// </summary>
        /// <param name="pagesize"></param>
        /// <param name="startindex"></param>
        /// <returns></returns>
        public List<LoggingInfo> GetLogList(int pagesize, int startindex)
        {
            List<LoggingInfo> loglist = new List<LoggingInfo>();
            LoggingInfo loginfo;
            DataSet ds = new DataAccessLogging().GetLogList(pagesize, startindex);
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                loginfo = new LoggingInfo() { LogName = dr[1].ToString(), LogPassword=dr[2].ToString(),
                                              PasswordConfirm = dr[3].ToString(), PasswordHint=dr[4].ToString(),
                                              LogDt = Convert.ToDateTime(dr[5]), IsLocked=dr[6].ToString(),
                                              LockDt = Convert.ToDateTime(dr[7]),RoleName=dr[8].ToString() };
                loglist.Add(loginfo);
            }
            return loglist;
        }

        /// <summary>
        /// 获取登录用户的数量
        /// </summary>
        /// <returns></returns>
        private int GetLogCount()
        {
            DataAccessLogging dalog = new DataAccessLogging();
            return dalog.GetLogCount();
        }
        /// <summary>
        /// 绑定用户到角色
        /// </summary>
        /// <param name="logid"></param>
        /// <param name="roleid"></param>
        /// <returns></returns>
        public int BindUserToRole(string logid, string roleid)
        {
            DataAccessLogging dalog = new DataAccessLogging();
            return dalog.BindUserToRole(logid, roleid);
        }
        /// <summary>
        /// 删除绑定
        /// </summary>
        /// <param name="logid"></param>
        /// <param name="roleid"></param>
        /// <returns></returns>
        public int NotBindUserToRole(string logid, string roleid)
        {
            DataAccessLogging dalog = new DataAccessLogging();
            return dalog.NotBindUserToRole(logid, roleid);
        }
    }
}
